<?php
/*
php标准格式；
学习模板！
*/
header("content-type:text/html;charset=UTF-8");
/*要先显示出来*/
require 'connect.php';
$_sql = "select * from students;";
$reques = mysql_query($_sql);
$rows = array();
 if(mysql_num_rows($reques))
 {
 	
 	while( $row = mysql_fetch_assoc($reques))
 	{
 		$rows[]=$row;
 	}

 }
 //var_dump($rows);
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>student-edit</title>
	<style type="text/css">
		body{
			background-color: #b4b4b4;
		}
		._table{
			text-align: center;
			line-height: 20px;
			background: #b4b4b4;
			border: 1px solid blue;
			margin: 0 auto;
		}
	</style>
</head>
<body>
	<table border="1px" class="_table">
		<th>学生编号</th>
		<th>学生姓名</th>
		<th>语文成绩</th>
		<th>数学成绩</th>
		<th>英语成绩</th>
		<th>删除操作</th>
		<th>修改操作</th>
		<?php foreach ($rows as $key => $value) :?>
		<tr>
		<td><?=$value['id']?></td>
		<td><?=$value['name']?></td>
		<td><?=$value['chinese']?></td>
		<td><?=$value['math']?></td>
		<td><?=$value['english']?></td>
		<td><a  href="delete.php?id=<?=$value['id']?>&name=<?=$value['name']?>" onclick="return deleteBook(this);">删除</a></td>
		<td><a  href="edit.php?id=<?=$value['id']?>&name=<?=$value['name']?>">修改</a></td>
		</tr>
	<?php endforeach;?>
	</table>
</body>
<script type="text/javascript">
	//删除某一行的函数
	function deleteBook(obj)
	{
		if(window.confirm("你真的要删除吗"))
		{
			//首先找到被删除的节点
			var del_obj = obj.parentNode.parentNode;
			//查找可以删除节点的父节点
			var father = del_obj.parentNode;
			//删除了
			father.removeChild(del_obj);
			return true;
		}
		return false;
	}
</script>
</html>
